#include "player.h"
#include "guard.h"
#include "statsMenu.h"
#include "playersExtraData.h"
#include <iostream>
#include <vector>


int main()
{
	Player player;
	player.image("player.png");
	player.X(200.0f);
	player.Y(150.0f);

	PlayersExtraData playersExtraData;

	StatsMenu statsMenu;
	statsMenu.X(200);
	statsMenu.Y(100);

	Guard guard;
	guard.image("guard.png");
	guard.X(400.0f);
	guard.Y(300.0f);

	Guard guard2;
	guard2.image("guard.png");
	guard2.X(100.0f);
	guard2.Y(100.0f);
	
	// Create the main rendering window
    sf::RenderWindow app(sf::VideoMode(800, 600, 32), "Test engine");
	app.SetFramerateLimit(60);
	app.UseVerticalSync(true);	
    
	sf::Image bg;
	bg.LoadFromFile("background.png");
	sf::Sprite bgs;
	bgs.SetImage(bg);
	bgs.SetPosition(0.0f, 0.0f);

	bool gamePaused = false;
    // Start game loop
    while (app.IsOpened())
    {
        // Process events and inputs
        sf::Event Event;
        while (app.GetEvent(Event))
        {
            //Close the window when escape events occur.
            if(Event.Type == sf::Event::Closed)
                app.Close();
			if(Event.Key.Code == sf::Key::Escape)
				app.Close();

			//this represents the top right front button on the 
			//logitec game controller.
			if(Event.Key.Code == sf::Key::E)
				app.Close();
        }

		//if the user presses button 4, then we open the stats menu up
		if(statsMenu.menuOn())
		{
			statsMenu.Input(app.GetInput());
			gamePaused = true;
		}
		else
		{
			gamePaused = false;
			playersExtraData.statsMenu = &statsMenu;
			player.Input(app.GetInput(), &playersExtraData);
		}


		std::vector<DrawableObject *> objectManager;

		//push enemys and NPCs on first
		objectManager.push_back(&guard);
		objectManager.push_back(&guard2);
		//Next push Player on
		objectManager.push_back(&player);
		//Then push Over head NPCs on
		//--put over head NPCs here
		//Finally push stats and other pause menus on
		objectManager.push_back(&statsMenu);
		
		////////////////////////////////////////////
		//Drawing begins here
		////////////////////////////////////////////

		//Backround and level 1 images are drawn here
		app.Draw(bgs);

		//Player and level 2 images are drawn here
		for(int i = 0; i < (int)objectManager.size(); i++)
		{
			//if the game is paused then only draw the stats
			//menu from the objectManager
			if(gamePaused)
			{
				objectManager.at(objectManager.size() - 1)->draw(app);
			}
			else
			{
					objectManager.at(i)->draw(app);
			}
		}
		//player.draw(app);
		//guard.draw(app);

		//Aerial and level 3 images are drawn here


            
        // Display window contents on screen
        app.Display();
    }

    return EXIT_SUCCESS;

	
	return 0;
}